package com.kfc.sales;

import java.util.List;
import java.util.Vector;




import android.app.Activity;
import android.app.ListActivity;
import android.content.Context;
import android.net.ParseException;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class SearchLocation extends ListActivity{
	private LayoutInflater mInflater;
	private Vector<RowData> data;
	RowData rd;
	static final String[] kfcbranches = new String[] {
	    "Manila", "Quezon City",	"Cebu","Davao", "Cavite", "Makati", "Mandaluyong", "Pasig", "Taguig", "Las Pinas"    	};

	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.selectbranchbylocation);
		mInflater = (LayoutInflater) getSystemService(
				Activity.LAYOUT_INFLATER_SERVICE);
			
			data = new Vector<RowData>();
			
			for(int i=0;i<kfcbranches.length;i++){
				try {
				 	rd = new RowData(kfcbranches[i]);
				    } catch (ParseException e) {
				    	e.printStackTrace();
				   }
				   data.add(rd);
			}
					
					CustomAdapter adapter = new CustomAdapter(this, R.layout.lists,
					                                     R.id.branchloc, data);
					
					setListAdapter(adapter);
					getListView().setTextFilterEnabled(true);
	}


	
	 public class RowData {
	       protected String mLocation;
	       
	       RowData(String location)
	       {
	    	   mLocation=location;
	       }
	
	}
	  
 public class CustomAdapter extends ArrayAdapter<RowData> {
	  public CustomAdapter(Context context, int resource,
	                        int textViewResourceId, List<RowData> objects) {               
	 super(context, resource, textViewResourceId, objects);
	}
	      @Override
	       public View getView(int position, View convertView, ViewGroup parent) {   
	       ViewHolder holder = null;
	       TextView loc = null;
	       RowData rowData= getItem(position);
	       if(null == convertView){
	            convertView = mInflater.inflate(R.layout.locationlist, null);
	            holder = new ViewHolder(convertView);
	            convertView.setTag(holder);
	        }
	             holder = (ViewHolder) convertView.getTag();
	             loc = holder.getprodname();
	             loc.setText(rowData.mLocation);
	             return convertView;
	       }
	            private class ViewHolder {
	            private View mRow;
	            private TextView loca = null;
	            public ViewHolder(View row) {
	            mRow = row;
	 }
	         public TextView getprodname() {
	             if(null == loca){
	                 loca = (TextView) mRow.findViewById(R.id.location);
	                }
	            return loca;
	         }
	     }
	   }

}
